package com.carryGo.web.hzl;

import com.carryGo.entity.Commodity;
import com.carryGo.service.hzl.IndexService;
import com.carryGo.utils.hzl.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * ClassName:IndexServlet
 * package:com.carryGo.web.hzl
 * Description:
 *
 * @Date:2020/8/25 14:04
 * @Author: tank_黄志凌
 */
@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    private IndexService indexService=new IndexService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String method=request.getParameter("method");
        switch (method){
            case "toIndex":
                WebUtils.toRequestPage(request,response,"index");
                break;
            case "toFoodPage":
                WebUtils.toRequestPage(request,response,"foodPage");
                break;
            case "toLiangyoufushi":
                WebUtils.toRequestPage(request,response,"liangyoufushi");
                break;
            case "toCosmeticsPage":
                WebUtils.toRequestPage(request,response,"cosmeticsPage");
                break;
            case "toErshoushichang":
                WebUtils.toRequestPage(request,response,"ershoushichang");
                break;
            case "toCanyinyule":
                WebUtils.toRequestPage(request,response,"canyinyule");
                break;
            case "toOnlineShopping":
                WebUtils.toRequestPage(request,response,"onlineShopping");
                break;
            case "toShoppCart":
                WebUtils.toRequestPage(request,response,"shoppCart");
                break;
            case "toOrder":
                WebUtils.toRequestPage(request,response,"order");
                break;
            case "queryComm":
                queryComm(request,response);
                break;
        }
    }

    private void queryComm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String commName = request.getParameter("search-name");
        List<Commodity> queryComm= indexService.queryComm(commName);
        System.out.println(queryComm);
        session.setAttribute("comm",queryComm);
        WebUtils.toRequestPage(request,response,"searchPage");

    }
}
